<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="myTags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="/resources/css/common.css">
<link rel="stylesheet" href="/resources/css/button.css">
<link rel="stylesheet" href="/resources/css/jquery.treeview.css">
<script type="text/javascript" src="/resources/js/jquery.js"></script>
<script type="text/javascript" src="/resources/js/jquery.treeview.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("#browser").treeview();
});

function upwardRelocate() {
	$('#modifyCategoryForm').attr({action:'category/upwardRelocate', method:'post'}).submit();
}

function downwardRelocate() {
	$('#modifyCategoryForm').attr({action:'category/downwardRelocate', method:'post'}).submit();
	
}
</script>
<title>Category</title>
</head>
<body>
<jsp:include page="../common/gnb.jsp"/>
<jsp:include page="../common/header.jsp"/>

<ul id="browser" class="treeview">
<c:if test="${not empty categoryTree}">
<c:choose>
<c:when test="${not empty categoryTree.id}">
	<li>
	${categoryTree.name}(${fn:length(categoryTree.children)})(${categoryTree.orderNo})
	<myTags:category children="${categoryTree.children}"/>
	</li>
</c:when>
<c:otherwise>
	<c:forEach items="${categoryTree.children}" var="row" varStatus="status">
	<li>
	${row.name}(${fn:length(row.children)})(${row.orderNo})
	<myTags:category children="${row.children}"/>
	</li>
	</c:forEach>
</c:otherwise>
</c:choose>
</c:if>
</ul>

<form:form modelAttribute="category" action="category/create">
upper:<form:select path="parentId" items="${categoryList}" itemValue="id" itemLabel="name"/>
name: <form:input path="name"/>
<input type="submit" value="전송"/>
</form:form>

<form:form modelAttribute="category" action="category/delete">
id:<form:select path="id" items="${categoryList}" itemValue="id" itemLabel="name"/>
<input type="submit" value="전송"/>
</form:form>

<form:form id="modifyCategoryForm" modelAttribute="category" action="category/modify">
id:<form:select path="id" items="${categoryList}" itemValue="id" itemLabel="name"/>
upperid:<form:select path="parentId" items="${categoryList}" itemValue="id" itemLabel="name"/>
name:<form:input path="name"/>
<input type="button" onclick="upwardRelocate()"/>
<input type="button" onclick="downwardRelocate()"/>
<input type="submit" value="전송"/>
</form:form>
<jsp:include page="../common/footer.jsp"/>
</body>
</html>